$("#initiatingOrderEdit").validate({
	rules:{
		xxxx:{
			required:true,
		},
	},
	submitHandler:function(form){
		edit();
	}
});

function edit() {
	var orderId = $("input[name='orderId']").val();
	var typeId = $("select[name='productType'] option:selected").val();
	var specId = $("select[name='specId']").val();
	var productId = $("select[name='infoId']").val();
	var typeName = $("select[name='productType'] option:selected").text();
	var fullName = $("select[name='productType'] option:selected").text()+'-'+$("select[name='specId'] option:selected").text()+'-'+$("select[name='infoId'] option:selected").text();
	if(typeId==''||typeId==null){
		debugger
		layer.msg('请选择产品类型!')
	}else if(specId==''||specId==null){
		debugger
		layer.msg('请选择产品品种!')
	}else if(productId==''||productId==null){
		debugger
		layer.msg('请选择产品名称!')
	}else{
		$.ajax({
			cache : true,
			type : "POST",
			url : ctx + "module/order/initiatingOrder",
			data : {
				"orderId" : orderId,
				"typeId" : typeId,
				"specId" : specId,
				"productId" : productId,
				"typeName" : typeName,
				"fullName" : fullName,
			},
			async : false,
			error : function(request) {
				$.modalAlert("系统错误", "error");
			},
			success : function(data) {
				if (data.code == 0) {
					parent.layer.msg("提交成功,正在刷新数据请稍后……",{icon:1,time: 500,shade: [0.1,'#fff']},function(){
						$.parentReload();
					});
				} else {
					$.modalAlert(data.msg, "error");
				}
			}
		});
	}
}

function changeSelect(){
	var typeId = $("select[name='productType']").val();
	if(typeId!='' && typeId!=null&& typeId!="请选择" ){
		$.ajax({
	        type: "GET",
	        url: ctx + "module/order/selectList",
	        data : {
	        	"typeId": typeId
	        },
	        success: function(result) {
	        	//获取第二个下拉框的对象
	        	var spec = document.getElementById('specId');
	        	//获取第三个下拉框的对象
	        	var spec1 = document.getElementById('infoId');
	        	//每次获取数据前先清空
	        	$(spec).empty();
	        	//每次获取数据前先清空
	        	$(spec1).empty();
	        	$("#productPrice").val('');         			
	    		$("#productTerm").val(''); 
	        	for(var i=0;i<result.length;i++){//循环遍历数组
	        		//将数组的值依次赋给第二个下拉框
	        		spec[i] = new Option(result[i].specName,result[i].specId);
				}
	        }
	    });
	}			
}


function changeSelectInfo(){
	var specId = $("select[name='specId']").val();
	var productId = $("select[name='infoId']").val();
	if(specId!='' && specId!=null &&specId!="请选择"){	
		$.ajax({
	        type: "GET",
	        url: ctx + "module/order/selectProductList",
	        data : {
	        	"specId": specId
	        },
	        success: function(result) {
	        	//获取第三个下拉框的对象
	        	var spec = document.getElementById('infoId');
	        	//每次获取数据前先清空
	        	$(spec).empty();
	        	$("#productPrice").val('');         			
	    		$("#productTerm").val(''); 
	        	for(var i=0;i<result.length;i++){//循环遍历数组
	        		//将数组的值依次赋给第二个下拉框
	        		spec[i] = new Option(result[i].productName,result[i].productId);        			        				        		
				}
	        	
	        }
	    });
	}
	
}

function changeSelectPriceTerm(){
	var productId = $("select[name='infoId']").val();
	$.ajax({
        type: "GET",
        url: ctx + "module/order/selectPriceTerm",
        data : {
        	"productId": productId
        },
        success: function(result) {
        	var data = JSON.parse(result)  
        		$("#productPrice").val(data.productPrice);         			
        		$("#productTerm").val(data.productTerm); 
        
        	
        }
    });
	
}
